package service

import (
	"gitee.com/wao520/obtain_data/cache"
	"gitee.com/wao520/obtain_data/dao"
	"gitee.com/wao520/obtain_data/model"
	"github.com/go-redis/redis"
)

// 得到一篇文章的详情
func GetOneArticle(articleId uint64) (*model.Article, error) {
	//get from cache
	article, err := cache.GetOneArticleCache(articleId)
	if err == redis.Nil || err != nil {
		//get from mysql
		article, errSel := dao.SelectOneArticle(articleId)
		if errSel != nil {
			return nil, errSel
		} else {
			//set cache
			errSet := cache.SetOneArticleCache(articleId, article)
			if errSet != nil {
				return nil, errSet
			} else {
				return article, errSel
			}
		}
	} else {
		return article, err
	}

	//get from mysql
	// article, errSel := dao.SelectOneArticle(articleId)
	// return article, errSel
}
